import java.io.*; 
import java.net.InetAddress;
import java.net.UnknownHostException;



public class VlcReceptor {
	public static String vlcpath = new String();
	public static VLCControler vlc;
	public static void main(String[] args) throws IOException{
		final Server server = new Server();
		//new Thread(server).start();
		CaminhoVlc caminho = new CaminhoVlc();
		  InetAddress ia = null;     
		       try {     
		          ia = InetAddress.getLocalHost();     
		       } catch (UnknownHostException e) {     
		          e.printStackTrace();     
		       }     
		   
		 String ip = ia.getHostAddress();  
		caminho.abrir();
		String canal = new String();
		boolean mute=false;
		while(true){
			server.receber();
			if(Server.message!=null && Server.message.split("@")[3].contains("?play:")){
				System.out.println("aqui");
				try{
					canal = Server.message.split(":")[2];
				}
				catch (Exception e) {canal = "null";}
				vlc.comando("add http://" + Server.message.split(":")[1] + ":8080/" + canal);	
				vlc.comando("loop on");
				vlc.comando("f");
			}
			if(Server.message!=null && Server.message.split("@")[3].equals("?full")){
				vlc.comando("f");
			}
			if(Server.message!=null && Server.message.split("@")[3].equals("?up")){
				vlc.comando("volup 5");
			}
			if(Server.message!=null && Server.message.split("@")[3].equals("?down")){
				vlc.comando("voldown 5");
			}
			if(Server.message!=null && Server.message.split("@")[3].equals("?mute")){
				if (mute) {
					vlc.comando("volume 100");
					mute = false;
				}
				else
				{
					vlc.comando("volume 0");
					mute = true;
				}
			}
			if(Server.message!=null && Server.message.split("@")[3].equals("?stop")){
				vlc.comando("stop");
			}
			if(Server.message!=null && Server.message.split("@")[3].equals("?who")){
				Client.enviar(ip);
			}
			try {Thread.sleep(50);}
			catch (Exception e) {e.printStackTrace();}
			Server.message=null;
		}
	}
}
